<template>
  <div class="question" v-if="info != ''">
    <!-- 下拉菜单 -->
    <van-dropdown-menu>
      <van-dropdown-item ref="city">
        <!-- slot="title/default" -->
        <template #title>
          <div class="title">
            <span class="t1"> 面试宝典 </span>
            <span class="t2">{{ city }} </span>
          </div>
        </template>
        <template>
          <van-index-bar>
            <!-- 对象的key转换成数据 Object.keys(对象) -->
            <div v-for="(item, index) in Object.keys(info.citys)" :key="index">
              <van-index-anchor :index="item" class="anchor">
              </van-index-anchor>
              <van-cell
                v-for="(item2, index2) in info.citys[item]"
                :key="index2"
                :title="item2"
                @click="cellClick(item2)"
              >
              </van-cell>
            </div>
          </van-index-bar>
        </template>
      </van-dropdown-item>
    </van-dropdown-menu>

    <div class="content">
      <div class="nav">
        <van-tag
          v-for="(item, index) in info.cityPositions[city]"
          :key="index"
          class="tag"
          color="#f7f4f5"
          text-color="#7d7e92"
          :class="{ active: currIndex === index }"
          @click="currIndex = index"
        >
          {{ item.name }}</van-tag
        >
      </div>
    </div>

    <!-- 顺序刷题 -->
    <div class="middle">
      <div class="middle-item left-top">
        <div class="circle">
          <i class="iconfont icon">&#xe64f;</i>
        </div>
        <div class="txt">常错题库</div>
      </div>

      <div class="middle-item left-bottom">
        <div class="circle">
          <i class="iconfont icon">&#xe64f;</i>
        </div>
        <div class="txt">常错题库</div>
      </div>

      <div class="middle-item right-top">
        <div class="circle">
          <i class="iconfont icon">&#xe64f;</i>
        </div>
        <div class="txt">常错题库</div>
      </div>

      <div class="middle-item right-bottom">
        <div class="circle">
          <i class="iconfont icon">&#xe64f;</i>
        </div>
        <div class="txt">常错题库</div>
      </div>
      <!-- 中间圆 -->
      <div class="middle-center">
        <van-circle
          v-model="rate"
          :rate="endRate"
          :speed="50"
          class="vancircle"
          :size="120 / 37.5 + 'rem'"
          layer-color="none"
          :color="gradientColor"
        >
          <div class="other">
            <div class="o1">顺序刷题</div>
            <div>{{ getCollectTotal }}/{{ info.totalCount }}</div>
          </div>
        </van-circle>
      </div>
    </div>
    <div class="bottom">
      <div class="btn_1">累计收录</div>
      <h3 class="btn_2">23,456,245,000</h3>
      <van-button
        type="info"
        color="#00b8d4"
        block
        class="btn_3"
        @click="goInfo"
        >模拟面试</van-button
      >
    </div>
  </div>
</template>

<script>
import { interviewFilters } from '@/api/question.js'
//import {mapGetters,mapMutations,mapActions} from 'veux   //导入mapMutations与mapActions导入
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters(['getCollectTotal'])
  },
  data () {
    return {
      currIndex: 0, //存储当前岗位点击项的索引
      city: '全国',
      info: '',
      rate: 0,
      endRate: 30,

      gradientColor: {
        '0%': 'rgba(228,1,55,0.7)',
        '100%': 'rgba(228,1,55,0.3)'
      }
    }
  },
  async created () {
    const res = await interviewFilters()
    this.info = res.data.data
    window.console.log('城市数据:', res)
  },
  methods: {
    //城市点击
    cellClick (str) {
      this.city = str
      /* 点击事件处理:给city赋值同时关闭弹窗 */
      /* 通过调用van-dropdown-item的toggle方法关掉下拉选项 */
      this.$refs.city.toggle(false)
      /* 切换城市时,让点击项的索引回到第一个也就是currIndex=0 */
      this.currIndex = 0
    },
    /* 点击模拟面试*/
    goInfo () {
      /* 在点击模拟 面试跳转时,通过路由传参传入了type与city */
      this.$router.push('/home/questionInfo?type='+
      this.info.cityPositions[this.city][this.currIndex].id+'&city='+this.city
      )
    }
  }
}
</script>

<style lang="less" scoped>
.question {
  .title {
    .t1 {
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      text-align: left;
      color: #222222;
      line-height: 25px;
      letter-spacing: 0px;
    }
    .t2 {
      font-size: 12px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: center;
      color: #545671;
      line-height: 16px;
    }
  }
  .content {
    padding: 0 @p15;
    margin-top: 10px;
    margin-bottom: 10px;
    .nav {
      overflow-x: auto;
      padding: 10px 0;
      display: flex;
      .tag {
        flex-shrink: 0;
        padding: 6px 8px;
        margin-right: 15px;
      }
      .active {
        background-color: #00b8d4 !important;
        color: #fff !important;
      }
    }
  }
  .middle {
    position: relative;

    .circle {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      padding: 9px;
      color: #fff;
      background: linear-gradient(180deg, #ff8080, #ff4949);
      .icon {
        font-size: 24px;
      }
    }
    .txt {
      font-size: 12px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 500;
      text-align: left;
      color: #545671;
      line-height: 16px;
      letter-spacing: 0px;
      margin-top: 10px;
      text-align: center;
    }
    .left-top {
      top: 15px;
      position: absolute;
      left: 35px;
    }
    .left-bottom {
      bottom: -180px;
      position: absolute;
      left: 35px;
    }
    .right-top {
      top: 15px;
      position: absolute;
      right: 35px;
    }
    .right-bottom {
      bottom: -180px;
      position: absolute;
      right: 35px;
    }
    .middle-center {
      margin-top: 100px;
      position: absolute;
      width: 120px;
      height: 120px;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: url(~@/assets/123.png);
      background-size: 100%;

      .vancircle {
        width: 100% !important;
        height: 100% !important;
      }
      .other {
        width: 100px;
        height: 100px;
        font-size: 16px;
        color: #ffffff;
        display: flex;
        margin: 10px;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        border-radius: 50%;
        background-color: #fa5e84;
      }
    }
  }
  .bottom {
    text-align: center;
    margin-top: 220px;
    padding: 20px @p15;
    .btn_1 {
      margin-bottom: 20px;
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      color: #545671;
      line-height: 25px;
    }
    .btn_2 {
      margin-bottom: 20px;
      font-size: 30px;
      font-weight: 600;
      color: #545671;
      line-height: 42px;
      letter-spacing: 1px;
    }
  }
}
</style>
